﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;

namespace GPCSC.Web.sjsbyes
{
    public partial class MQRJTJEdit : PageBase 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Usual.f_querystringToString("command") != "" && (Usual.f_querystringToString("command") != null))
                {
                    this.MtxtD_tabids.Value = Usual.f_querystringToString("newsid");
                 
                    if (Usual.f_querystringToString("command") == "view")//查看
                    {
                        Button1.Style.Add("display", "none");
                    }
                    else//修改
                    {

                    }
                    DD1.Visible = false;
                    DD2.Visible = false;
                    f_fristLoad(this.MtxtD_tabids.Value);
                }
                else
                {
                    this.MtxtD_tabids.Value = Guid.NewGuid().ToString();
                  //  builddd1();
                  //  builddd2();
                    //this.MtxtD_lgname.Style.Add("display","none");
                    this.tes1.Style.Add("display", "none");

                }
            }
        }
        protected void f_fristLoad(string PrimaryKey)
        {
            base.o_uiTable.Clear();
            SqlReadXml org = new SqlReadXml();
            base.o_uiTable.Add("@tabids", PrimaryKey);
            base.m_uiDataSet = org.ReaderDataSet("sel_mqrj_one", base.o_uiTable);
            if (base.m_uiDataSet.Tables.Count > 0)
            {
                if (base.m_uiDataSet.Tables[0].Rows.Count > 0)
                {
                    //UIFactory set UI controls value:界面工厂设置界面控件值
                    try
                    {
                        base.o_uiTable = UIFactory.UIFactory_Set(this, base.m_uiDataSet.Tables[0]);

                    }
                    catch
                    {

                    }
                    this.tes1.Value = base.m_uiDataSet.Tables[0].Rows[0]["hdtitile"].ToString();
                    //your can do databind yourself:对界面工厂不能填充的数据，通过ODRM手动填充
                }
            }
        }
        protected void builddd1()//绑定活动
        {
            Hashtable htable = new Hashtable();
            DataSet ds = new DataReturn().ReturnData(htable, "sel_hdlist_all");
           // this.MtxtD_hdid.Value = ds.Tables[0].Rows[0]["hdsid"].ToString();
            DD1.DataSource = ds;
            DD1.DataBind();
        }
        protected void builddd2()//绑定人员
        {
            Hashtable htable = new Hashtable();
            DataSet ds = new DataReturn().ReturnData(htable, "sel_user_all");
        //    this.MtxtD_lgid.Value = ds.Tables[0].Rows[0]["CL_USER_SOID"].ToString();
            this.MtxtD_lgname.Value = ds.Tables[0].Rows[0]["USERNAME"].ToString();
            DD2.DataSource = ds;
            DD2.DataBind();
        }
        protected void editnews()//修改
        {
            try
            {
                base.o_uiTable.Clear();
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();

                dtable.databyhtables(base.o_uiTable, "update", "WW_MQ", "tabids", this.MtxtD_tabids.Value);
                this.Response.Write("<script>alert('修改成功！');window.location.href='MQRJTJ.aspx';</script>");
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
  

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Usual.f_querystringToString("command") != "" && Usual.f_querystringToString("command") != null)
            {
                editnews();
            }
            else
            {
                saveNews();
            }
        }
        /// <summary>
        /// 保存新闻
        /// </summary>
        protected void saveNews()
        {
            try
            {
                base.o_uiTable.Clear();
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                dtable.databyhtables(base.o_uiTable, "add", "WW_MQ", "", "");

                this.Response.Write("<script>alert('添加成功！');window.location.href='MQRJTJ.aspx';</script>");
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
    }
}